package org.example.springaop;

import org.example.springaop.house.IHouse;
import org.example.springaop.house.RealHouse;
import org.example.springaop.proxy.CGLibMethodInterceptor;
import org.example.springaop.proxy.JDKInvocationHandler;
import org.springframework.cglib.proxy.Enhancer;

import java.lang.reflect.Proxy;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 九转苍翎
 * Date: 2025/8/1
 * Time: 22:07
 */
public class Main {

    public static void main1(String[] args) {
        IHouse target = new RealHouse();
        //JDK动态代理,只能代理接口
        IHouse iHouse = (IHouse)Proxy.newProxyInstance(
                RealHouse.class.getClassLoader(),
                new Class[]{IHouse.class},
                new JDKInvocationHandler(target)
        );
        iHouse.rent();
        iHouse.sell();
    }

    public static void main(String[] args) {
        RealHouse target = new RealHouse();
        RealHouse realHouse = (RealHouse)Enhancer.create(
                RealHouse.class,
                new CGLibMethodInterceptor(target)
        );
        realHouse.rent();
        realHouse.sell();
    }
}